package guiLayer;

import guiLayer.extensions.ForestTreeModel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import modelLayer.Forest;
import controlerLayer.ForestCtr;


public class ReadForest extends Reader {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<Forest> forests;
	private ForestTreeModel model;
	/**
	 * Create the panel.
	 */
	public ReadForest() {
		btnClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				txtItem1.setText("");
			}
		});
		txtItem1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				searchForest(txtItem1.getText());
			}
		});
		btnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				searchForest(txtItem1.getText());
			}
		});
		forests = new ArrayList<Forest>();
		model = new ForestTreeModel(forests);
		tree.setModel(model);
		
		
		
		lblTitle.setText("Forests");
		lblItem.setText("Name");
		
	}
	
	public void searchForest(final String name){
		Thread t = new Thread(){
			public void run(){
				ForestCtr fCtr = new ForestCtr();
				model = new ForestTreeModel(fCtr.searchForest(name));
				tree.setModel(model);
			}
		};
		
		t.start();
	}
	
	@Override
	protected void updateData(){
		searchForest(txtItem1.getText());
	}
	
}
